package com.red.wood.service.task;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class WsTask {
	
	private static final Log log = LogFactory.getLog(WsTask.class);
	
	public void doTask(){
		System.err.println("========任务执行开始======");
		String URL = "http://localhost:8091/display-web/services/WsExample";
		String result = getCxfClientResponse(URL,"getUndoList", new String []{"int0","int1","int2"}, new String []{"zs","20","男"});
		log.info(result);
	}
	
	protected String getCxfClientResponse(String url,String method,String[]argNames,String...args){
		String result = "";
		try{
			Service service = new Service();
			Call call = (Call)service.createCall();
			call.setUseSOAPAction(true);
			call.setOperationStyle(org.apache.axis.constants.Style.WRAPPED);
			call.setOperationUse(org.apache.axis.constants.Use.LITERAL);
			call.setTargetEndpointAddress(url);
			//call.setTimeout(100000);
			call.setOperationName(method);
			
			if(argNames != null){
				for(String argName : argNames)
					call.addParameter(argName, org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
			}			
			call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
			
			result = (String)call.invoke(args);
		}
		catch (Exception e) {
			if(log.isErrorEnabled()){
				log.error(e.getMessage(),e);
			}
		}
		return result;
	}
}
